package ufo.api.common

import java.io.Serializable

case class Position(x:Int, y:Int) {
  def move(direction : Direction) = {
    Position(x+direction.x, y+direction.y)
  }

	def directionTo(other: Position): Option[Direction] = {
		val direction = List(NorthEast, NorthWest, SouthEast, SouthWest, North, South, West, East)

		direction.find(d => {
			this.move(d) equals other
		})
	}
}

abstract class Direction(val x : Int, val y : Int) extends Serializable

case object NorthEast extends Direction(1, -1)
case object NorthWest extends Direction(-1, -1)
case object SouthEast extends Direction(1, 1)
case object SouthWest extends Direction(-1, 1)
case object North extends Direction(0, -1)
case object South extends Direction(0, 1)
case object West extends Direction(-1, 0)
case object East extends Direction(1, 0)



